package com.example.esp32;

import static android.content.ContentValues.TAG;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.example.esp32.databinding.ActivityMainBinding;
import com.google.android.material.snackbar.Snackbar;

public class MainActivity extends AppCompatActivity  {
    private ImageButton button;
    private ImageButton button2,tjsb,textView2;
    private ImageButton rgb;
    private ImageButton list;


    private ActivityMainBinding binding;
    int tta=0;

    int flag[]=new int[]{0};
    String[] text={"还没想好怎么写这个功能","说了还没想好怎么写","别点了！！！都说了还没想好怎么写！！！"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {

//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
//
        String A=bug.NoBug("佛祖保佑");
        System.out.println(A);
        textView2=findViewById(R.id.textView2);
        textView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Toast.makeText(MainActivity.this,""+text[tta],Toast.LENGTH_SHORT).show();
                tta++;
                if(tta>3){
                    tta=0;
                }
            }
        });
        setSupportActionBar(binding.toolbar);
        button = findViewById(R.id.button);
        button2 = (ImageButton)findViewById(R.id.button2);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(MainActivity.this,yg.class);
                startActivity(intent);

            }
        });
        rgb=(ImageButton)findViewById(R.id.rgb);
        rgb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,rgb.class);
                startActivity(intent);
            }
        });
        list=(ImageButton)findViewById(R.id.button3);
        list.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent();
                intent.setClass(MainActivity.this,list.class);

                startActivity(intent);

            }
        });
        tjsb=(ImageButton)findViewById(R.id.tjsb);
        tjsb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,additme.class);
                startActivity(intent);
            }
        });

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this,pew.class);
                startActivity(intent);
            }
        });
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main,menu); //通过getMenuInflater()方法得到MenuInflater对象，再调用它的inflate()方法就可以给当前活动创建菜单了，第一个参数：用于指定我们通过哪一个资源文件来创建菜单；第二个参数：用于指定我们的菜单项将添加到哪一个Menu对象当中。
        return true; // true：允许创建的菜单显示出来，false：创建的菜单将无法显示。
    }

    /**
     *菜单的点击事件
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Intent intent = new Intent();

        switch (item.getItemId()){
            case R.id.about:
                intent.setClass(MainActivity.this,about.class);
                startActivity(intent);
                break;
            case R.id.siz:
                intent.setClass(MainActivity.this,Settings.class);
                startActivity(intent);
                break;
            default:
                break;
        }

        return true;}

    private void onClickButton(View view) {
//        if(flag[0]==0){
//
////            String dataa="kai";
////            String resq=request.post("http://ipzhangt:8999/",dataa);
////            Log.d(TAG, resq);
////            views.setText(resq);
//
//        }//选中
//                else{
////            String data="guan";
////            String resq=request.post("http://ipzhangt:8999/",data);
////            Log.d(TAG, resq);
////            Log.d(TAG, data);
////            views.setText(resq);
//
//        }//取消

        new Thread(){
            public void run() {
                request request =new request();


                ImageButton but=findViewById(R.id.button);

                if(flag[0]==0){

                    String dataa="kai";
                    String resq=request.post("http://ipzhangt:8999/",dataa);
                    Log.d(TAG, resq);
//                    but.setText(R.string.guan);
                    flag[0]=1;
                }//选中
                else{
                    String data="guan";
                    String resq=request.post("http://ipzhangt:8999/",data);
                    Log.d(TAG, resq);
                    Log.d(TAG, data);
//                    but.setText(R.string.kai);
                    flag[0]=0;
                }//取消


            }public void tex() {

            }


        }.start();
    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {
        super.onPointerCaptureChanged(hasCapture);
    }

//    class MyThread extends Thread {
////        static String result;
//
//        public String run(String a){
//            String b=a;
//
//            Log.d(TAG,resq+"a" );
//            return resq;
//        }
//    }
//    public String onckl(String a){
//        new Thread(){


////                String data="qqzt";
////                String resq=request.post("http://ipzhangt:8999/",data);
////                view.setText(resq);
//
//                if (resq=="开"){
//                    String dataa="kai";
//                    String resqa=request.post("http://ipzhangt:8999/",dataa);
//
//                    but.setText(resqa);
//                } else if (resq=="关") {
//                    String datab="guan";
//                    String resqb=request.post("http://ipzhangt:8999/",datab);
//                    but.setText(resqb);


//                }
//
//            return run(a);
//        }.start();
//
//
//    }
//MyThread mt=new MyThread();

//    public void oncklc(View view) {
//        new Thread(){
//

//        }.start();
//
//        Thread.run("a");

//        mt.run("guan");
//        mt.start();
//        Log.d(TAG,b );

public void phone(){
//        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CHANGE_WIFI_MULTICAST_STATE)!= PackageManager.PERMISSION_GRANTED){
//            ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.CALL_PHONE},100);
//            Toast.makeText(MainActivity.this,"ok",Toast.LENGTH_SHORT).show();
//
//        }else {
//            Toast.makeText(MainActivity.this,"no",Toast.LENGTH_SHORT).show();
//
//        }

    ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.ACCESS_WIFI_STATE,Manifest.permission.CHANGE_WIFI_STATE,Manifest.permission.CHANGE_WIFI_MULTICAST_STATE,Manifest.permission.NEARBY_WIFI_DEVICES},300);

}
    }
